package cn.wdm.system.listenter;

import cn.wdm.system.service.IPermissionScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener//申明自定义的web监听器，被容器注册和使用
@Slf4j
public class PermissionScanInitListener implements ServletContextListener {
    @Autowired
    private IPermissionScanService permissionScanService;
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //1.监听类，在项目启动时做点什么 项目启动完成初始化
        //为了不影响springboot项目的正常运行，需要开启异步线程，让spring项目启动和项目初始化分开
        //单独开一个线程让初始化自己玩
        new Thread(new Runnable() {
            @Override
            public void run() {
                //初始化，交给业务层做
                permissionScanService.scanPermission();
            }
        }).start();

    }
}
